@extends('admin.layout.base')

@section('content')

    <div class="layui-form-item">
        <div class="layui-inline">
            <input class="layui-input search-data" name="name" placeholder="用户名" autocomplete="off">
        </div>

        <div class="layui-inline">
            <input class="layui-input search-data" name="email" placeholder="邮箱" autocomplete="off">
        </div>

        <div class="layui-inline layui-form">
            <select name="status" class="search-data">
                <option value="">状态</option>
                <option value="1">启用</option>
                <option value="2">停用</option>
            </select>
        </div>

        <div class="layui-inline demoTable">
            <button class="layui-btn layui-btn-sm layuiadmin-btn-useradmin" data-type="search" lay-filter="search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>
    </div>

    <div class="layui-card">

        <table class="layui-hide" id="tableData" lay-filter="myTable"></table>

        <script type="text/html" id="status">
            <a lay-event="status">
                <input type="checkbox" data-url="{{route("user.status")}}" data-id="switch_@{{d.id}}" value="@{{d.status}}" @{{d.status==1?'checked':''}} lay-skin="switch" lay-text="启用|停用">
            </a>
        </script>

        <script type="text/html" id="options">
            <div class="layui-btn-group">
                @can('user.edit')
                    <a data-url="{{route("user.edit")}}" lay-event="edit" class="layui-btn layui-btn-xs layui-btn-normal">编辑</a>
                @endcan
                @can('user.delete')
                    <a data-url="{{route("user.delete")}}" lay-event="del" class="layui-btn layui-btn-xs layui-btn-danger">删除</a>
                @endcan
            </div>
        </script>

    </div>

@endsection

@section('script')
    <script>
        layui.use(['table', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var table = layui.table;
            table.render({
                elem: '#tableData'
                , url: '{{route("user.list")}}'
                , cols: [[
                    {field: 'id', title: 'ID', sort: true, width: 60}
                    , {field: 'head_img', title: '头像', width: 65, templet: function (d) {
                            return '<img src="' + d.head_img.url + '" style="width: 30px;"> '
                        }
                    }
                    , {field: 'name', title: '用户名'}
                   // , {field: 'phone', title: '手机号'}
                    , {field: 'email', title: '邮箱'}
                    , {field: 'sex', title: '性别', width: 80, templet: function (d) {
                            return d.sex == 1 ? '男' : '女';
                        }
                    }
                    , {field: 'rank', title: '等级', width: 80}
                    , {field: 'created_at', title: '创建时间', width: 165}
                    , {field: 'status', title: '状态', toolbar: '#status', width: 100}
                    , {fixed: 'right', title: '操作', align: 'center', toolbar: '#options', width: 100}
                ]]
                , id: 'myReload'
                , page: true
            });
        });
    </script>
@endsection